<include file="Public:header" />
<tagLib name="html" />
<style type="text/css">
     .wrap-word{word-wrap:break-word;}
     td {
          white-space: pre-wrap;       /* css-3 */
           white-space: -moz-pre-wrap;  /* Mozilla, since 1999 */
            white-space: -pre-wrap;      /* Opera 4-6 */
             white-space: -o-pre-wrap;    /* Opera 7 */
              word-wrap: break-word;       /* Internet Explorer 5.5+ */
     }
</style>
<div id="main" class="main" >
<!-- 主体内容  -->
<div class="content" >
<!--  功能组区域  -->
<div class="btn-toolbar">
	<div class="btn-group">
		<button class="btn btn-primary" onclick="import_order()"> <i class="icon-share-alt  icon-white"></i>
		导入订单	
		</button>
		<button class="btn btn-primary" onclick="tocheck()"> <i class="icon-check icon-white"></i>
			待审核
		</button>
		<button class="btn btn-primary" onclick="add()"> <i class="icon-plus icon-white"></i>
			新增
		</button>
		<button class="btn btn-primary" onclick="toshipping()"> <i class="icon-check icon-white"></i>
			待平台发货
		</button>
	<button class="btn btn-primary" onclick="can_not_shipping()"> <i class="icon-exclamation-sign icon-white"></i>
			缺货
		</button>
		
		
		<button class="btn btn-primary" onclick="foreverdel()"> <i class="icon-trash icon-white"></i>
			删除
		</button>
<!--		
		<button class="btn btn-primary" onclick="sync()"> <i class="icon-circle-arrow-up icon-white"></i>
			同步药房网
		</button>
		<button class="btn btn-primary" onclick="sync_dst()"> <i class="icon-circle-arrow-up icon-white"></i>
			同步德生堂
		</button>
        -->
		<!--
		<button class="btn btn-primary" onclick="manual_add_gift()"> <i class="icon-heart icon-white"></i>
			绑定赠品
		</button>
        
		<button class="btn btn-primary" onclick="pick_goods()"> <i class="icon-shopping-cart  icon-white"></i>拣货单</button>		
		<button class="btn btn-primary" onclick="shipping()"> <i class="icon-download-alt  icon-white"></i>快递单</button>
		<button class="btn btn-primary" onclick="mass_doshipping()"> <i class="icon-plane  icon-white"></i>闪电发货</button>
        -->
        <button class="btn btn-primary" onclick="invoice()"> <i class="icon-tags  icon-white"></i>配货单</button>
		<button class="btn btn-primary" onclick="doshipping()"> <i class="icon-forward  icon-white"></i>发货</button>
		<button class="btn btn-primary" onclick="mass_reshipping()"> <i class="icon-road  icon-white"></i>平台补发货</button>
		<button class="btn btn-primary" onclick="loudan()"> <i class="icon-question-sign  icon-white"></i>漏单查询</button>
        <button class="btn btn-success" onclick="send_message()"> <i class="icon-envelope  icon-white"></i>群发短信</button>
        <a class="btn btn-info" href="__URL__/archive"><i class="icon-list  icon-white"></i>历史订单</a>
	</div>
		导出
		<a href="__URL__/export_order?{$parameters}&etype=order&action={:ACTION_NAME}" class="btn">订单</a>
		<a href="__URL__/export_order?{$parameters}&etype=detail&action={:ACTION_NAME}" class="btn">商品</a>
		<a href="__URL__/export_order?{$parameters}&etype=both&action={:ACTION_NAME}" class="btn">全部</a>
		<span class="label label-success">总销售额:{$sum_should_pay}</span>
	<form class="search-form" method='get' action="__URL__">
		来源{:modList( 'Order_source',$_REQUEST['order_source_id'],'span1', 'order_source_id' )}
		运单<input type="text" class="search-query span2" name="logino" <notempty name='_REQUEST.logino'>
		<php>echo 'value="'.urldecode($_REQUEST['logino']).'"'</php>
		<else/>
		placeholder="运单号" </notempty> >
	   收货人<input type="text" class="search-query span2" name="shipping_name" <notempty name='_REQUEST.shipping_name'>
		<php>echo 'value="'.urldecode($_REQUEST['shipping_name']).'"'</php>
		<else/>
		placeholder="收货人" </notempty> >

	   手机<input type="text" class="search-query span2" name="mobile" <notempty name='_REQUEST.mobile'>
		<php>echo 'value="'.urldecode($_REQUEST['mobile']).'"'</php>
		<else/>
		placeholder="手机" </notempty> >

	   买家<input type="text" class="search-query span2" name="customer_name" <notempty name='_REQUEST.customer_name'>
		<php>echo 'value="'.urldecode($_REQUEST['customer_name']).'"'</php>
		<else/>
		placeholder="买家" </notempty> >

	订单号
	<input type="text" class="search-query span2" name="order_no" <notempty name='_REQUEST.order_no'>
		<php>echo 'value="'.urldecode($_REQUEST['order_no']).'"'</php>
		<else/>
		placeholder="按订单号搜索"
	</notempty>
	>
    <!--Advaced Search-->
     <div  id="searchM" class=" none search cBoth" >
		每页显示 <input type="text" class="span1" name="listRows" value="{$_REQUEST.listRows}">
		订单状态{:configList( C('orderStatus'),$_REQUEST['order_status'],'order_status','span1' )}
		仓库{:modList( 'Warehouse',$_REQUEST['warehouse_id'],'span1','warehouse_id' )}
		
		<select name="status" class="span1"> 
			<option value="">--审核状态--</option>
			<option value="1" <eq name="_REQUEST.status" value="1">selected</eq> >审核通过</option> 
			<option value="0" <eq name="_REQUEST.status" value="0">selected</eq> >待审核</option> 
		</select>

		备注<input type="text" class="search-query span2" name="remark" <notempty name='_REQUEST.remark'>
		<php>echo 'value="'.urldecode($_REQUEST['remark']).'"'</php>
		<else/>
		placeholder="备注" </notempty> >

	   地址<input type="text" class="search-query span2" name="address" <notempty name='_REQUEST.address'>
		<php>echo 'value="'.urldecode($_REQUEST['address']).'"'</php>
		<else/>
		placeholder="地址" </notempty> >


	   电话<input type="text" class="search-query span2" name="phone" <notempty name='_REQUEST.phone'>
		<php>echo 'value="'.urldecode($_REQUEST['phone']).'"'</php>
		<else/>
		placeholder="电话" </notempty> >

		<select name="time_type" class="span1"> 
			<option value="">--时间类型--</option>
			<option value="1" <eq name="_REQUEST.time_type" value="1">selected</eq> >审核时间</option> 
			<option value="2" <eq name="_REQUEST.time_type" value="2">selected</eq> >发货时间</option> 
			<option value="3" <eq name="_REQUEST.time_type" value="3">selected</eq> >下单时间</option> 
			<option value="4" <eq name="_REQUEST.time_type" value="4">selected</eq> >支付时间</option>
		</select>
		从<input type="text" class="span2"  name="start_time" onClick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" value="<notempty name='_REQUEST.start_time'>{$_REQUEST.start_time}</notempty>">
		到<input type="text" class="span2" onClick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" name="end_time" id="end_time" value="<notempty name='_REQUEST.end_time'>{$_REQUEST.end_time}</notempty>" >
		销售标题<input type="text" class="search-query span3" name="keywords" <notempty name='_REQUEST.keywords'>
		<php>echo 'value="'.urldecode($_REQUEST['keywords']).'"'</php>
		<else/>
		placeholder="商品销售标题,空格搜索"
	</notempty> >
		产品名称<input type="text" class="search-query span3" name="product_name" <notempty name='_REQUEST.product_name'>
		<php>echo 'value="'.urldecode($_REQUEST['product_name']).'"'</php>
		<else/>
		placeholder="产品名称,支持空格搜索"
	</notempty> >

	模糊订单号
	<input type="text" class="search-query span2" name="like_order_no" <notempty name='_REQUEST.like_order_no'>
		<php>echo 'value="'.urldecode($_REQUEST['like_order_no']).'"'</php>
		<else/>
		placeholder="按订单号模糊搜索"
	</notempty>
	>
     </div>
	<input type="submit" class="btn btn-primary input-middle" value="搜  索">
    <a class="btn btn-info" onclick="showHideSearch()" href="javascript:void(0)" ><i class="icon-chevron-down icon-white"></i> 更多</a>
	</form>
	
</div>
<!-- 功能组区域结束 -->
<php>
     
    function getWare($warehouse_id){
       $cache_warehouse = S('warehouse');
        echo $cache_warehouse[$warehouse_id];
    }

    function add_order($id){
    echo ('<a href="__APP__/Sale/add/id/'.$id.'">增补订单</a>');
    }
    function editLink($id){
     echo ('<a href="__APP__/Sale/edit/id/'.$id.'">'.getModelName($id,"Sale","sale_no").'</a>');
	}

	//mall to shipping and show add_gift status
	function tmall_shipping($id){
		$sale = M('Sale')->getById($id);
		/*if( 0 == $sale['is_shipping_mall'] && $sale['order_status'] ==3 ){
			$express = getModelName( $sale['logicompany_id'],'Logicompany' );
            $shipping_str = ( '<a href="javascript:void(0)" onclick="setshipping('.$id.','.$sale['sale_no'].')" style="color:red">平台发货</a> ' );
		}*/
        if( 1 == $sale['got_gift'] || 1 == $sale['got_over_gift'] ){
           $gift_str = '<span class="label label-success">赠品</span> ';
        }
			echo $gift_str. $shipping_str;
	}
</php>
<!-- 列表显示区域  -->
<div class="list" >
<div id="result" class="result none"></div><html:list id="checkList" pk="id" action="true" style="table table-bordered table-striped" checkbox="true"  datasource="list" show="id|editLink:订单号|4%,mall_no|word_wrap:原单号,warehouse_id|getWare:仓库,address:地址,id|tmall_shipping:赠品,should_pay:应收款,sum_number:总数,shipping_name:收货人,customer_msg|cutstr=50:客户留言|10%,logicompany_id|getModelName='Logicompany':配送公司,logino:运单号,order_status|getConfigVal=orderstatus:订单状态,remark|cutstr=50:备注|10%,create_time|toDate:下单时间,check_time|toDate:审核时间,shipping_time|toDate:发货时间,order_source_id|getModelName='Order_source':订单来源,status|getStatus:审核,id|add_order:增补订单" actionlist="refund:退款:id"/>
</div>
<!--  分页显示区域 -->
<div class="page">{$page}</div>
<!-- 列表显示区域结束 -->
</div>
<!-- 主体内容结束 -->
</div>
<include file="Public:footer"/>
<load href="__PUBLIC__/Js/My97DatePicker/WdatePicker.js" />
<script type="text/javascript">
	//增录产品
  function addpt(id){
    window.open( APP+"/Sale_detail/add/id/"+id, '_blank' );
  }
  function addWholesale(){
    window.open( APP+"/Sale/addWholesale/", '_blank' );
  }

  //待平台发货的订单
  function toshipping(){
    window.open( URL+"/toshipping", '_blank' );
  }

  //缺货不能发货的订单
  function can_not_shipping(){
    //window.open( URL+"/can_not_shipping", '_blank' );
    window.open( APP+"/OutStock/index", '_blank' );
  }
  //同步药房网订单
  function sync(){
    window.open( URL+"/sync_yaofang", '_blank' );
  }
  //同步德生堂订单
  function sync_dst(){
    location.href =  APP+"/OrderAPI/sync_dst";
  }

  //平台已发货
  function setshipping(id,sale_no,express,logino){
	if (id=='')
	{
		alert('请选择订单！');
		return false;
	}
	//TODO 只有等待发货的订单才能改变为平台已发货状态
	window.open("http://dealer.yaofang.cn/order/detail/"+sale_no,'_blank');
    //location.href = URL+"/setFieldValue/id/"+id+"/field/is_shipping_mall/new/1";
        
}

  //填写快递单号，TODO置为发货状态
  function doshipping(id){
  var keyValue = (id)? id : getSelectCheckboxValues();
	if (keyValue=='')
	{
		alert('请选择订单！');
		return false;
	}
    window.open( APP+"/ToShipping/doshipping/oid/"+keyValue, '_blank' );
  }

//批量填写快递单号，TODO置为发货状态
  function mass_doshipping(id){
  var keyValue = (id)? id : getSelectCheckboxValues();
	if (keyValue=='')
	{
		alert('请选择订单！');
		return false;
	}
    window.open( APP+"/Sale/mass_doshipping/oid/"+keyValue, '_blank' );
  }

  function import_order(){
    location.href= APP+'/Sale/tbimport';
 }

 function invoice(id){
 	var keyValue = (id)? id : getSelectCheckboxValues();
	if (keyValue=='')
	{
		alert('请选择订单！');
		return false;
	}
        window.open(APP+"/ToShipping/invoice/oid/"+keyValue,'_blank' );
 }
 function shipping(id){
 	var keyValue = (id)? id : getSelectCheckboxValues();
	if (keyValue=='')
	{
		alert('请选择订单！');
		return false;
	}
        location.href = URL+"/shipping/oid/"+keyValue;
 }
 function pick_goods(id){
 	var keyValue = (id)? id : getSelectCheckboxValues();
	if (keyValue=='')
	{
		alert('请选择订单！');
		return false;
	}
        window.open( URL+"/pick_goods/oid/"+keyValue , '_blank' );
 }

 function send_message(id){
 	var keyValue = (id)? id : getSelectCheckboxValues();
	if (keyValue=='')
	{
		alert('请选择订单！');
		return false;
	}
        location.href =  URL+"/send_message/id/"+keyValue;
 }
 function tocheck(){
 	 location.href = URL+"/index/order_status/2/status/0/_order/create_time/_sort/1";
}
function mass_reshipping(){
	window.open( APP+"/OrderAPI/all_reshipping", '_blank' );
}
function manual_add_gift(){
	location.href =  APP+"/Gift/auto_mass_add_gift";
}
function edit_shipping(id){
    location.href= URL+"/edit_shipping/id/"+id;
}
function refund(id){
    location.href= APP+"/Refund/add/id/"+id;
}
function loudan(id){
    location.href= URL+"/import_loudan";
}
</script>
